import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "reset-css";
import moment from "moment";
import api from "./api/requst";


// import AmapVue from '@amap/amap-vue'

// AmapVue.config.key = 'cdd615c7a4a3f11e66caed4732b2ea7a'
// Vue.use(AmapVue)

// 动态标题
import VueWechatTitle from "vue-wechat-title";
Vue.use(VueWechatTitle);

// 滑块，轮播
import vueSwiper from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
Vue.use(vueSwiper)

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);


//api配置
Vue.prototype.$post = function(url, param = {}) {
    var headers = {
        token: store.state.token || "111111"
    };
    // console.log(store)
    if (process.env.NODE_ENV === "production") {
        return api.POST(url, headers, param);
    } else {
        // console.log(`=========== 数据请求【${url}】 ============`)
        // console.log('headers：' + JSON.stringify(headers));
        // consle.log('参数：' + JSON.stringify(param));
        return api.POST(url, headers, param).then(res => {
            // console.log('返回值：', res);
            return res;
        });
        // return new Promise((resolve, reject)=> {
        //     "use strict";
        //     api.POST(url, headers, param).then(res=> {
        //         console.log('返回值：', res);
        //         resolve(res);
        //     });
        // });
    }
};
Vue.prototype.$put = function(url, param = {}) {
    var headers = {
        token: store.state.token || ""
    };
    // console.log(store)
    if (process.env.NODE_ENV === "production") {
        return api.PUT(url, headers, param);
    } else {
        // console.log(`=========== 数据请求【${url}】 ============`)
        // console.log('headers：' + JSON.stringify(headers));
        // consle.log('参数：' + JSON.stringify(param));
        return api.PUT(url, headers, param).then(res => {
            // console.log('返回值：', res);
            return res;
        });
        // return new Promise((resolve, reject)=> {
        //     "use strict";
        //     api.POST(url, headers, param).then(res=> {
        //         console.log('返回值：', res);
        //         resolve(res);
        //     });
        // });
    }
};
Vue.prototype.$get = function(url, param = {}) {
    url +=
        "?" +
        Object.keys(param)
            .map(k => `${k}=${param[k]}`)
            .join("&");
    param = {};
    var headers = {
        token: store.state.token || ""
    };
    if (process.env.NODE_ENV === "production") {
        return api.GET(url, headers, param);
    } else {
        // console.log(`=========== 数据请求【${url}】 ============`)
        // console.log('headers：' + JSON.stringify(headers));
        // console.log('参数：' + JSON.stringify(param));
        return api.GET(url, headers, param).then(res => {
            // console.log('返回值：', res);
            return res;
        });
        // return new Promise((resolve, reject)=> {
        //     "use strict";
        //     api.POST(url, headers, param).then(res=> {
        //         console.log('返回值：', res);
        //         resolve(res);
        //     });
        // });
    }
};

Vue.filter("momentFormat", function(value, format) {
    if (!value) {
        return "";
    }
    return moment(value).format(format);
});

Vue.config.productionTip = false;

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount("#app");
